package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.ProductSpecMapper;
import com.atguigu.spzx.manager.service.ProductSpecService;
import com.atguigu.spzx.model.entity.product.ProductSpec;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName: ProductSpecServiceImpl
 * @Package: com.atguigu.spzx.manager.service.impl
 * @Description
 * @Author 孤妤
 * @Date: 2023/12/8 11:27
 */
@Service
@Transactional
public class ProductSpecServiceImpl implements ProductSpecService {
    @Autowired
    private ProductSpecMapper productSpecMapper;
    @Override
    @Transactional(readOnly = true)
    public PageInfo<ProductSpec> findProductSpecPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<ProductSpec> productSpecList = productSpecMapper.selectProductSpecPage();
        return new PageInfo<>(productSpecList);
    }

    @Override
    public void addProductSpec(ProductSpec productSpec) {
        productSpecMapper.insertProductSpec(productSpec);
    }

    @Override
    public void changeProductSpecById(ProductSpec productSpec) {
        productSpecMapper.updateProductSpec(productSpec);
    }

    @Override
    public void removeProductSpecById(Long id) {
        productSpecMapper.deleteProductSpecById(id);
    }

    @Override
    @Transactional(readOnly = true)
    public List<ProductSpec> findAll() {
        return productSpecMapper.selectProductSpecPage();
    }
}
